const express = require("express");

const pool = require("../pool.js");

const r = express.Router();

// 首页接口
r.get("/index_Interface", (req, res) => {
  let sql_index_carousel = "select * from index_carousel;";
  // 首页轮播图数据
  pool.query(sql_index_carousel, (err, carousel_result) => {
    if (err) throw err;
    console.log(carousel_result);
    let sql_index_category = "select * from index_category;";
    // 首页导航数据
    pool.query(sql_index_category, (err, category_result) => {
      if (err) throw err;
      console.log(category_result);
      // 首页专区数据
      let sql_index_specialarea = "select * from index_specialarea;";
      pool.query(sql_index_specialarea, (err, specialarea_result) => {
        if (err) throw err;
        console.log(specialarea_result);
        res.send({
          code: 200,
          msg: "ok",
          carousel: carousel_result,
          category: category_result,
          specialarea: specialarea_result,
        });
      });
    });
  });
});

module.exports = r;
